#ifndef __HELLOWORLD_SCENE_H__
#define __HELLOWORLD_SCENE_H__

#include "cocos2d.h"
#include "Box2D/Box2D.h"
#include "SimpleAudioEngine.h"
#include "EndScene.h"
#include "ui/CocosGUI.h"
#include "StartScene.h"

#define PTM_RATIO 32
#define GOLD_NUM_MAX 10

class HelloWorld : public cocos2d::Layer
{
    b2World* world;

public:

	~HelloWorld();
    
	// there's no 'id' in cpp, so we recommend returning the class instance pointer
    static cocos2d::Scene* createScene();

    // Here's a difference. Method 'init' in cocos2d-x returns bool, instead of returning 'id' in cocos2d-iphone
    virtual bool init();

	virtual void update(float dt);
	virtual bool onTouchBegan(cocos2d::Touch* touch, cocos2d::Event* event);
	virtual void onTouchEnded(cocos2d::Touch* touch, cocos2d::Event* event);
	virtual void onTouchMoved(cocos2d::Touch* touch, cocos2d::Event* event);
	virtual void draw(cocos2d::Renderer *renderer, const cocos2d::Mat4& transform, uint32_t flags);   //重写draw函数
	// implement the "static create()" method manually
    CREATE_FUNC(HelloWorld);
	
	void initPhysics();									//初始化物理引擎
	void addNewSpriteAtPosition(cocos2d::Point p);   //添加天平对象
	void addNewSprite(cocos2d::Point p);             //添加玩家
	int productRandom(int start,int end);			//产生随机数
	void initGold();                                //初始化金币
	bool collisionSprite(cocos2d::Sprite *a,cocos2d::Sprite *b);  //碰撞检测
	void initScore();               //初始化分数
	void scoreOut();               //分数显示更新
	void transf(float dt);
	void playE(float dt);
	void onKeyReleased(cocos2d::EventKeyboard::KeyCode keycode, cocos2d::Event* event);
	virtual void heBacktouchEvent(cocos2d::Object *pSender, cocos2d::ui::TouchEventType type);
	


	b2Body *player;  //玩家刚体
	float den;      //玩家密度
	cocos2d::Sprite *spritePlayer;    //玩家精灵
	cocos2d::Sprite *gold[GOLD_NUM_MAX];    //金币对象数组
	int pos;					//保存位置
	//GLESDebugDraw *debugDraw;   //调试绘图对象
	cocos2d::Size windo;       //屏幕大小
	int ran;					//随机数
	bool aLive;    //金币是否为活动状态
	int v;			//金币下降速率
	int distance;	//金币下降间隔
	bool drop;      //玩家掉落
	int fenshu;     //分数

	cocos2d::Sprite *score[5];    //分数精灵

	//开始背景
	cocos2d::Sprite* jin;
	cocos2d::Sprite* mid;
	cocos2d::Sprite* yuan;
	float ji;
	float mi;
	float yu;
	float vg;//滚动速度
	//判断左右
	bool left;
	bool right;

	cocos2d::ui::Button* heBack;    //返回主标题

};

#endif // __HELLOWORLD_SCENE_H__